using System.IO;

namespace Engine.FileFormats3D.C11Undercover.QADFile
{
    public class Object
    {
        #region Private Fields

        private float ausrichtung1;
        private float ausrichtung2;
        private float ausrichtung3;
        private float cosisnus;
        private float keineAhnung;
        private byte[] keineAhnung2 = new byte[4];
        private byte[] keineAhnung3 = new byte[4];
        private byte[] keineAhnung4 = new byte[8];
        private ObjectName name;
        private float negativerCosinus;
        private float negativerSinus;
        private int objectPropertieID;
        private float positionX;
        private float positionY;
        private float positionZ;
        private float sinus;
        private float size;

        #endregion Private Fields

        #region Public Constructors

        public Object(string name, int ObjectPropertyId, float x, float y, float z)
        {
            this.ausrichtung1 = 0.0f;
            this.ausrichtung2 = 0.0f;
            this.ausrichtung3 = 0.0f;
            this.cosisnus = 0.0f;
            this.keineAhnung = 0.0f;
            //byte[] keineAhnung2 = new byte[4];
            //byte[] keineAhnung3 = new byte[4];
            //byte[] keineAhnung4 = new byte[8];
            this.name = new ObjectName(name);
            this.negativerCosinus = 0.0f;
            this.negativerSinus = 0.0f;
            this.objectPropertieID = ObjectPropertyId;
            this.positionX = x;
            this.positionY = y;
            this.positionZ = z;
            this.sinus = 0.0f;
            this.size = 1.0f;
        }

        public Object()
        {
            this.ausrichtung1 = 0.0f;
            this.ausrichtung2 = 0.0f;
            this.ausrichtung3 = 0.0f;
            this.cosisnus = 0.0f;
            this.keineAhnung = 0.0f;
            //byte[] keineAhnung2 = new byte[4];
            //byte[] keineAhnung3 = new byte[4];
            //byte[] keineAhnung4 = new byte[8];
            this.name = new ObjectName("not defined!");
            this.negativerCosinus = 0.0f;
            this.negativerSinus = 0.0f;
            this.objectPropertieID = 0;
            this.positionX = 0.0f;
            this.positionY = 0.0f;
            this.positionZ = 0.0f;
            this.sinus = 0.0f;
            this.size = 1.0f;
        }

        #endregion Public Constructors

        #region Public Methods

        public override string ToString()
        {
            return this.name.ToString();
        }

        #endregion Public Methods

        #region Internal Methods

        internal static Object FromStream(BinaryReader br)
        {
            long positionStart = br.BaseStream.Position;
            Object obj = new Object();
            obj.name = ObjectName.FromStream(br);
            obj.objectPropertieID = br.ReadInt32();
            obj.positionX = br.ReadSingle();
            obj.positionY = br.ReadSingle();
            obj.positionZ = br.ReadSingle();
            obj.keineAhnung = br.ReadSingle();
            obj.size = br.ReadSingle();
            obj.cosisnus = br.ReadSingle();
            obj.keineAhnung2 = br.ReadBytes(4); ;// war 0
            obj.sinus = br.ReadSingle();
            obj.ausrichtung1 = br.ReadSingle();// 0 vieleicht keine Ahnung
            obj.ausrichtung2 = br.ReadSingle();// 1
            obj.ausrichtung3 = br.ReadSingle();// 0
            obj.negativerSinus = br.ReadSingle();
            obj.keineAhnung3 = br.ReadBytes(4);
            obj.negativerCosinus = br.ReadSingle();
            obj.keineAhnung4 = br.ReadBytes(8);
            br.BaseStream.Position += 12;
            positionStart = br.BaseStream.Position - positionStart;
            return obj;
        }

        internal void Save(BinaryWriter bw)
        {
            this.name.Save(bw); //obj.name = ObjectName.LoadFromStream(br);
            bw.Write(this.objectPropertieID);//obj.objectPropertieID = br.ReadInt32();
            bw.Write(this.positionX);//obj.positionX = br.ReadSingle();
            bw.Write(this.positionY);//obj.positionY = br.ReadSingle();
            bw.Write(this.positionZ);//obj.positionZ = br.ReadSingle();
            bw.Write(this.keineAhnung);//obj.keineAhnung = br.ReadSingle();
            bw.Write(this.size);//obj.size = br.ReadSingle();
            bw.Write(this.cosisnus); //obj.cosisnus = br.ReadSingle();
            bw.Write(this.keineAhnung2);//obj.keineAhnung2 = br.ReadBytes(4); ;// war 0
            bw.Write(this.sinus); //obj.sinus = br.ReadSingle();
            bw.Write(this.ausrichtung1);   //obj.ausrichtung1 = br.ReadSingle();// 0 vieleicht keine Ahnung
            bw.Write(this.ausrichtung2); //obj.ausrichtung2 = br.ReadSingle();// 1
            bw.Write(this.ausrichtung3); //obj.ausrichtung3 = br.ReadSingle();// 0
            bw.Write(this.negativerSinus); //obj.negativerSinus = br.ReadSingle();
            bw.Write(this.keineAhnung3);//obj.keineAhnung3 = br.ReadBytes(4);
            bw.Write(this.negativerCosinus); //obj.negativerCosinus = br.ReadSingle();
            bw.Write(this.keineAhnung4);//obj.keineAhnung4 = br.ReadBytes(8);
        }

        #endregion Internal Methods
    }
}